package 牛客网_N.动态规划.数组单调和_9;

import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int n = Integer.parseInt(in.nextLine());
		String str = in.nextLine();
		String dataStr[] = str.split(" ");
		int[] A = new int[n];
		for(int i = 0; i < n; i++){
			A[i] = Integer.parseInt(dataStr[i]);
		}
		System.out.println(calcMonoSum(A, n));
	}
	
	public static int calcMonoSum(int[] A, int n){
		int sum = 0;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < i; j++){
				if(A[j] <= A[i]) sum += A[j];
			}
		}
		return sum;
	}
}
